<%@ page import="cn.school.service.StudentService" %>
<%@ page import="cn.school.entity.Student" %>
<%@ page import="cn.school.service.GradeService" %>
<%@ page import="cn.school.entity.Grade" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %><%--
  Created by IntelliJ IDEA.
  User: ghost
  Date: 2019/12/8
  Time: 18:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-3.4.1.min.js"></script>
</head>
<body>
<%@include file="checkLogin.jsp"%>
<%
    int id = Integer.parseInt(request.getParameter("id"));
    StudentService ss= new StudentService();
    Student s= ss.selectById(id);
%>
<form action="update.jsp" method="post" enctype="multipart/form-data">
    <table cellpadding="10">
        <input type="text" name="id" value="<%=id%>" hidden>
        <input type="text" name="oldidcardpic" value="<%=s.getIdcardpic()%>" hidden>
        <tr><td>姓名：</td><td><input type="text" name="sname" required value="<%=s.getSname()%>"></td></tr>
        <tr><td>性别：</td><td><input type="radio" name="sex" value="男">男<input type="radio" name="sex" value="女">女<input type="radio" name="sex" value="妖">妖</td></tr>
        <tr><td>电话号码：</td><td><input type="text" name="telephone" value="<% if(s.getTelephone()!=null)out.print(s.getTelephone());%>"></td></tr>
        <tr><td>qq：</td><td><input type="text" name="qq" value="<%if(s.getQq()!=null)out.print(s.getQq());%>"></td></tr>
        <tr><td>微信：</td><td><input type="text" name="wechat" value="<%if(s.getWechat()!=null)out.print(s.getWechat());%>"></td></tr>
        <tr><td>年级：</td><td>
            <select name="gradeid">
                <%
                    GradeService gs = new GradeService();
                    List<Grade> list = gs.findAll();
                    for(Grade g:list){
                        if(g.getId() == s.getGradeid()){%>
                            <option value="<%=g.getId()%>" selected="selected"><%=g.getGname()%></option>
                       <% }
                %>
                <option value="<%=g.getId()%>"><%=g.getGname()%></option>
                <% }%>
            </select>
        </td></tr>
        <tr><td>籍贯：</td><td><input type="text" name="fromcity" value="<%if(s.getFromcity()!=null)out.print(s.getFromcity());%>"></td></tr>
        <tr><td>出生日期：</td><td><input id="birthday" type="date" name="birthday" value="<%
            Date date = s.getBirthday();
            if(date != null){
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                out.print(sdf.format(date));
            }
        %>"></td></tr>
        <tr><td>现居地：</td><td><input type="text" name="address" value="<%if(s.getAddress()!=null)out.print(s.getAddress());%>"></td></tr>
        <tr><td>登录密码：</td><td><input type="text" name="pass" value="<%if(s.getPass()!=null)out.print(s.getPass());%>" required></td></tr>
        <tr><td>身份证照片：</td><td><input type="file" name="sfile" accept="jpg/png/gif"><img id="image" width="200px" height="100px" src="../img/<%=s.getIdcardpic()%>"></td></tr>
        <tr><td><input type="submit" value="修改"></td></tr>
    </table>
</form>
<script>
    $(function(){
        $(":radio[name=sex][value='<%=s.getSex()%>']").prop("checked",true);
    });
</script>
</body>
</html>
